#pragma once

class CWindow : public Singleton<CWindow>
{
	friend class D3DManager;
	ui32 m_posx, m_posy, m_sizex, m_sizey;
	ui32 m_clientX, m_clientY;
	WNDCLASSEX m_wndclass;
	HCURSOR mCurStandard, mCurAnim;
	bool mAnimatedCursor;
	bool mMouseInClient;

	static LRESULT __stdcall WndProc(HWND hWindow, UINT uMsg, WPARAM, LPARAM);

	HWND m_hWindow;
	bool m_running;

	static std::map<HWND, CWindow*> sWindows;
	ui32 m_lastRender;
	float mAspectRatio;

	HCURSOR getAnimatedCursor(ui32 id);
	void handleMouseEnter();
	void onMouseMove();

public:
	CWindow(ui32 x, ui32 y, ui32 dx, ui32 dy);

	void BeginShow();
	void setCursor(bool animated);

	operator HWND()
	{
		return m_hWindow;
	}

	POINT GetSize()
	{
		POINT p;
		p.x = m_sizex;
		p.y = m_sizey;
		return p;
	}

	void Destroy()
	{
		m_running = false;
	}

	ui32 GetPosX() { return m_posx; }
	ui32 GetPosY() { return m_posy; }
	ui32 GetClientX() { return m_clientX; }
	ui32 GetClientY() { return m_clientY; }
};

#define sWindow (*CWindow::GetInstance())